package com.wzb.eye100.util;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class JsonUtils {


    public static String loadConfig(String filePath) {
        InputStream is = null;
        ByteArrayOutputStream bos = null;
        try {
            is = new FileInputStream(new File(filePath));
            bos = new ByteArrayOutputStream();
            byte[] b = new byte[1024];
            int len;
            while ((len = is.read(b)) != -1) {
                bos.write(b, 0, len);
            }
            return bos.toString("utf-8");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bos != null)
                    bos.close();
                if (is != null)
                    is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;

    }

    public static String loadConfig2(String filePath) {
        InputStream fis = null;
        BufferedReader reader = null;
        try {
            fis = new FileInputStream(new File(filePath));
            reader = new BufferedReader(new InputStreamReader(fis));

            StringBuilder data = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {

                if(line.trim().startsWith("//")){

                }else {
                    data.append(line).append("\n");
                }
            }

            return data.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            try {
                if (reader != null) {
                    reader.close();
                }
                if(fis!=null){
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

        return null;

    }


}
